from rest_framework.serializers import ModelSerializer

from areas.models import Area


class AreaSerializer(ModelSerializer):
    """查询所有省份用到的序列化器"""

    class Meta:
        model = Area
        fields = ('id', 'name')


class SubAreaSerializer(ModelSerializer):
    """查询一条区域数据时用到的序列化器"""
    subs = AreaSerializer(many=True, read_only=True)

    class Meta:
        model = Area
        fields = ('id', 'name', 'subs')